#include "Menu.h"
#include "SnakeWorld.h"
#include "SnakeWorld2.h"
#include "Choose.h"
#include "Options.h"
using namespace cocos2d;

CCScene* Menu::scene()
{
	CCScene *scene = NULL;
	do
	{
		scene = CCScene::create();
		CC_BREAK_IF(!scene);
		Menu *layer = Menu::create();
		CC_BREAK_IF(!layer);
		scene->addChild(layer);
	} while (0);
	return scene;
}

bool Menu::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!CCLayer::init());

		CCSize size = CCDirector::sharedDirector()->getWinSize();
		CCSprite *mu = CCSprite::create("menu.jpg");
		CC_BREAK_IF(!mu);
		mu->setPosition(ccp(size.width/2,size.height/2));
		this->addChild(mu,0);

		CCLabelTTF *pStart = CCLabelTTF::create("BEGIN","Segoe Marker",24);
		CC_BREAK_IF(!pStart);

		CCLabelTTF *pOption = CCLabelTTF::create("OPTION","Segoe Marker",24);
		CC_BREAK_IF(!pOption);

		CCLabelTTF *pClose = CCLabelTTF::create("EXIT","Segoe Marker",24);
		CC_BREAK_IF(!pClose);

		CCMenuItemLabel *pStartItem = CCMenuItemLabel::create(pStart,this,menu_selector(Menu::startGame));
		CC_BREAK_IF(!pStartItem);
		pStartItem->setPosition(ccp(size.width/2 + 60,size.height/2 + 30));

		CCMenuItemLabel *pOptionItem = CCMenuItemLabel::create(pOption,this,menu_selector(Menu::gameOption));
		CC_BREAK_IF(!pOptionItem);
		pOptionItem->setPosition(ccp(size.width/2 + 60,size.height/2 - 10));

		CCMenuItemLabel *pCloseItem = CCMenuItemLabel::create(pClose,this,menu_selector(Menu::menuCloseCallBack));
		CC_BREAK_IF(!pCloseItem);
		pCloseItem->setPosition(ccp(size.width/2 + 60,size.height/2 - 50));

		CCMenu *MENU = CCMenu::create(pStartItem,pOptionItem,pCloseItem,NULL);
		MENU->setPosition(CCPointZero);
		CC_BREAK_IF(!MENU);
		this->addChild(MENU,1);

		bRet = true;
	}
	while(0);
	return bRet;
}
void Menu::startGame(CCObject* p)
{
	CCScene *s = Choose::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));
}


void Menu::menuCloseCallBack(CCObject* pSender)
{
	CCDirector::sharedDirector()->end();
}

void Menu::gameOption(CCObject* pSender)
{
	CCScene *s = Options::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionCrossFade::create(1,s));
}
